package com.yjhb.android.sbz.activity;

import android.graphics.drawable.Drawable;
import android.os.CountDownTimer;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.bumptech.glide.Glide;
import com.bumptech.glide.request.target.CustomTarget;
import com.bumptech.glide.request.transition.Transition;
import com.yjhb.android.sbz.R;
import com.jojo.android.zxlib.base.mvp.BasePresenter;
import com.jojo.android.zxlib.tool.ZxToast;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * 创建者 zx
 * 创建时间 2021/1/7 15:45
 */
public class MakeMoneyStrategyActivity extends BaseActivity {
    private final String TAG = "MakeMoneyStrategyActivity";

    @BindView(R.id.button)
    ImageView button;

    @BindView(R.id.content_layout)
    LinearLayout content_layout;

    private boolean isFinish = false;
    private CountDownTimer countDownTimer;
    private int state;

    @Override
    protected BasePresenter initPresenter() {
        return null;
    }

    @Override
    protected int getLayoutId() {
        return R.layout.activity_make_money_strategy;
    }

    @Override
    protected void initUI() {
        state = getIntent().getIntExtra("state", 0);
        loadingDialog.show();
        Glide.with(this).load("https://shangbangzhuan.oss-cn-beijing.aliyuncs.com/commonImages/make_money_bg.png")
                .into(new CustomTarget<Drawable>() {
                    @Override
                    public void onResourceReady(@NonNull Drawable resource, @Nullable Transition<? super Drawable> transition) {
                        loadingDialog.cancel();
                        if (content_layout != null) {
                            content_layout.setBackground(resource);
                        }
                    }

                    @Override
                    public void onLoadCleared(@Nullable Drawable placeholder) {

                    }
                });
    }

    @Override
    protected void initData() {
        countDownTimer = new CountDownTimer(1000 * 20, 1000) {
            @Override
            public void onTick(long millisUntilFinished) {

            }

            @Override
            public void onFinish() {
                isFinish = true;
                ZxToast.showSuccessBottomToast("任务完成，点击“立即赚钱”领取红包吧！");
            }
        };
        if (state == 1) {
            button.setVisibility(View.GONE);
        } else {
            countDownTimer.start();
        }
    }

    @Override
    protected void regEvent() {

    }

    @Override
    protected void onDestroy() {
        countDownTimer.cancel();
        super.onDestroy();
    }

    @OnClick(R.id.button)
    void button() {
        if (!isFinish) {
            ZxToast.showINFOBottomToast("浏览20s攻略就能领红包哦~~");
            return;
        }
        setResult(RESULT_OK);
        finish();
    }

    @OnClick(R.id.back)
    void back() {
        finish();
    }

}
